#!/usr/bin/python
import os
import sys
import shutil

from ComicBook import ComicBook
from ComicBookDownloader import ComicBookDownloader
from ConvertToPDF import ConvertImageFolderToPDF


def print_usage():
    print "Usage: %s comic_url" % os.path.split(sys.argv[0])[1]


def download_comic(url):
    comic_book = ComicBook(url)
    downloader = ComicBookDownloader(comic_book)
    downloader.download()

    print 'Finished downloading %s' % comic_book.title

    ConvertImageFolderToPDF(comic_book.title)
    shutil.rmtree(comic_book.title)

    print 'Converted images to PDF file %s.pdf' % comic_book.title

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print_usage()

    for url in sys.argv[1:]:
        download_comic(url)
